﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OS
{
    class Buffer
    {
        public enum TYPE { EMPTY, INPUTFUL, OUTPUTFUL };    // The only acceptable buffer types
        private TYPE type;                                // String to hold the buffer's type
        private String data;                                // String to hold the buffer's data

        /// <summary>
        /// Default constructor
        /// </summary>
        public Buffer()
        {
            type = TYPE.EMPTY;
            data = null;
        }

        /// <summary>
        /// Overloaded constructor
        /// </summary>
        /// <param name="t">The type of the buffer</param>
        /// <param name="d">The data in the buffer</param>
        public Buffer(TYPE t, String d)
        {
            if (!t.Equals(TYPE.EMPTY) && !t.Equals(TYPE.INPUTFUL) && !t.Equals(TYPE.OUTPUTFUL))
            {
                Console.WriteLine("Cannot set buffer type to " + t);
            }
            else
            {
                type = t;
            }

            data = d;
        }

        /// <summary>
        /// Getter/setter for type
        /// </summary>
        public TYPE Type
        {
            get { return type; }
            set
            {
                if (!value.Equals(TYPE.EMPTY) && !value.Equals(TYPE.INPUTFUL) && !value.Equals(TYPE.OUTPUTFUL))
                {
                    Console.WriteLine("Cannot set buffer type to " + value);
                }
                else
                {
                    type = value;
                }
            }
        }

        /// <summary>
        /// Getter/setter for data
        /// </summary>
        public String Data
        {
            get { return data; }
            set { data = value; }
        }

        /// <summary>
        /// Clears the buffer and sets the type to EMPTY
        /// </summary>
        public void ClearBuffer()
        {
            data = null;
            type = TYPE.EMPTY;
        }

        /// <summary>
        /// Checks to see if the buffer is empty
        /// </summary>
        /// <returns>True if the buffer is empty, otherwise false.</returns>
        public bool IsEmpty()
        {
            return data == null;
        }

        public static IFBBuffer ToIFBBuffer(Buffer b)
        {
            IFBBuffer ifbb = new IFBBuffer();

            ifbb.Data = b.data;
            ifbb.Type = IFBBuffer.TYPE.INPUTFUL;
            ifbb.F = ' ';

            return ifbb;
        }
    }
}
